import java.util.*;

/**
 * @author LKQ
 * @date 2022/6/19 11:15
 * @description 排序，统计个数
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution =  new Solution();
        int[] nums = {1, 2, 3, 4 , 5, 6, 7, 8, 9, 10};
        solution.reductionOperations(nums);
    }
    public int reductionOperations(int[] nums) {
        int[] cnt = new int[(int) 1e5];
        // 使用数组计数
        for (int num : nums) {
            cnt[num]++;
        }
        List<Integer> list = new ArrayList<>();
        // 将最大值，次大值加入list
        for(int i = (int) 1e5 - 1; i >= 0; i--) {
            if (cnt[i] != 0) {
                list.add(i);
            }
        }
        int sum = 0;
        int i = 0, before = 0;
        while (i < list.size() - 1) {
            // 当前数需要操作次数
            int cur = cnt[list.get(i)];
            sum += cur + before;
            // 对下一个较小数的影响
            before += cur;
            i++;
        }
        return sum;
    }
}
